package com.ourteam.product.requirement.api;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.requirement.dao.IProductVersionDAO;
import com.ourteam.product.requirement.dao.ProductVersionDAOQueryBean;
import com.ourteam.product.requirement.domain.ProductVersionBean;

public class ProductVersionSearchModel extends AbstractSearchModel<ProductVersionDAOQueryBean> {

	private long productDefineId;

	public long getProductDefineId() {
		return productDefineId;
	}

	public void setProductDefineId(long productDefineId) {
		this.productDefineId = productDefineId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductVersionBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductVersionDAOQueryBean queryBean) throws Exception {

		ProductVersionDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (productDefineId != 0) {
			criteria.andProductDefineIdEqualTo(productDefineId);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IProductVersionDAO.StartDate);
		}

	}

}
